<?php
$link = mysqli_connect('localhost', 'root', '123', 'Dress', '3306');
mysqli_query($link,"set names 'utf8'");
if(isset($_POST["add1"])) {
    $username = !empty($_POST['username']) ? $_POST['username'] : "";
    $password = !empty($_POST['password']) ? $_POST['password'] : "";
    $name = !empty($_POST['name']) ? $_POST['name'] : "";
    $age = !empty($_POST['age']) ? $_POST['age'] : "";
    $sex = !empty($_POST['sex']) ? $_POST['sex'] : "";
    $phone = !empty($_POST['phone']) ? $_POST['phone'] : "";
    $address = !empty($_POST['address']) ? $_POST['address'] : "";
    $sql = "select username from user where username = '$username'"; //SQL语句
    $result = mysqli_query($link,$sql);    //执行SQL语句
    $num = mysqli_num_rows($result); //统计执行结果影响的行数
    if ($num)    //如果已经存在该用户
    {
        echo "<script>alert('用户名已存在'); history.go(-1); </script>";
    } else    //不存在当前注册用户名称
    {
        $sql_insert = "insert into user (username,password,realname,age,sex,phonenum,address) values('$username','$password','$name','$age','$sex','$phone','$address')";
        $res_insert = mysqli_query($link,$sql_insert);
        //$num_insert = mysql_num_rows($res_insert);
        if ($res_insert) {
            echo "<script>alert('添加成功！');history.go(-1); </script>";
        } else {
            echo "<script>alert('系统繁忙，请稍候！');history.go(-1); </script>";
        }

    }
}
if(isset($_POST["add2"])) {
    $title = !empty($_POST['title']) ? $_POST['title'] : "";
    $type = !empty($_POST['type']) ? $_POST['type'] : "";
    $intro = !empty($_POST['intro']) ? $_POST['intro'] : "";
    $pic = !empty($_POST['pic']) ? $_POST['pic']: "";
    $pic= substr_replace($pic,"lib/webuploader/0.1.5/server/style/",0,0);
    $pic= substr_replace(".jpg",$pic,0,0);
    $sql_insert = "insert into style (title,type,introduce,pic) values('$title','$type','$intro','$pic')";
    $res_insert = mysqli_query($link,$sql_insert);
    //$num_insert = mysql_num_rows($res_insert);
    if ($res_insert) {
        echo "<script>alert('添加成功！');history.go(-1); </script>";
        } else {
        echo "<script>alert('系统繁忙，请稍候！');history.go(-1); </script>";
        }

}

if(isset($_POST["add3"])) {
    $title = !empty($_POST['title']) ? $_POST['title'] : "";
    $type = !empty($_POST['type']) ? $_POST['type'] : "";
    $price = !empty($_POST['price']) ? $_POST['price'] : "";
    $intro = !empty($_POST['intro']) ? $_POST['intro'] : "";
    $pic = !empty($_POST['pic']) ? $_POST['pic']: "";
    $pic= substr_replace($pic,"lib/webuploader/0.1.5/server/goods/",0,0);
    $pic= substr_replace(".jpg",$pic,0,0);
    $sql_insert = "insert into goods (name,type,price,introduction,pic) values('$title','$type','$price','$intro','$pic')";
    $res_insert = mysqli_query($link,$sql_insert);
    //$num_insert = mysql_num_rows($res_insert);
    if ($res_insert) {
        echo "<script>alert('添加成功！');history.go(-1); </script>";
    } else {
        echo "<script>alert('系统繁忙，请稍候！');history.go(-1); </script>";
    }

}

?>